package flowGraph;

import temp.TempList;
import assem.Instr;
import graph.Node;

public class AssemFlowGraph extends FlowGraph {
	java.util.Dictionary<Node, Instr> NImap = new java.util.Hashtable<Node, Instr>();

	public AssemFlowGraph(assem.InstrList instrs) {
		java.util.Dictionary<temp.Label, Node> LNmap = new java.util.Hashtable<temp.Label, Node>();
		Node tmp, last = null;
		assem.Targets t;

		for (assem.InstrList i = instrs; i != null; i = i.tail) {
			tmp = this.newNode();
			NImap.put(tmp, i.head);
			if (i.head instanceof assem.LABEL) 
				LNmap.put(((assem.LABEL)i.head).label, tmp);
			if (last != null) this.addEdge(last, tmp);
			last = tmp;
		}
		for (graph.NodeList i = nodes(); i != null; i = i.tail) 
			if ((t = NImap.get(i.head).jumps()) != null)
				for (temp.LabelList j = t.labels; j != null; j = j.tail)
					if (LNmap.get(j.head) != null) this.addEdge(i.head, LNmap.get(j.head));
	}

	public Instr instr(Node n) {
		return NImap.get(n);
	}

	public TempList def(Node node) {
		return instr(node).def();
	}

	public boolean isMove(Node node) {
		return (instr(node) instanceof assem.MOVE);
	}

	public TempList use(Node node) {
		return instr(node).use();
	}

}
